package com.nuanshui.heatedloan.userinfo.service;

import com.nuanshui.framework.consts.TransactionManagerType;
import com.nuanshui.heatedloan.userinfo.dal.mapper.UserContactMapper;
import com.nuanshui.heatedloan.userinfo.model.UserInfo;
import com.nuanshui.heatedloan.userinfo.tool.UserTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by zxh on 2017/2/10.
 */
@Service
public class UserContactServiceImpl {

    @Autowired
    private UserContactMapper userMapper;

    @Autowired
    private UserTool userTool;

    /**
     * 保存聊天信息
     */
    //@Override
    @Transactional(value= TransactionManagerType.USER_INFO_TRANSACTION_MANAGER)
    public void saveUserContact(String userId,Integer type) {
        String curUserId = userTool.getCurrentUser().getId();
        Long count = userMapper.isContacted(curUserId, userId,type);
        if(count>0) {
            userMapper.updateContactTime(curUserId, userId,type);
        }else {
            userMapper.saveUserContact(curUserId, userId,type);
        }

    }
    /**
     * 获取最近联系的人
     */
    //@Override
    public List<UserInfo> loadLatestContactUser(Pageable pageable) {
        return userMapper.loadLatestContactUser(userTool.getCurrentUser().getId(), pageable);
    }

    //@Override
    public List<Long> loadLatestTargetIds(String sourceUserId, Integer type,Pageable pageable) {
        return userMapper.loadLatestTargetIds(sourceUserId, type,pageable);
    }
}
